#include<bits/stdc++.h>
using namespace std;
int a[200005];
int h[1000005];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    for(int i=1;i<=T;i++){
        memset(h,0,sizeof(h));
        int n,ans=0;
        cin>>n;
        for(int j=1;j<=n;j++){
            cin>>a[j];
            h[a[j]]++;
            if(h[a[j]]>1){
                ans+=a[j];
                h[a[j]]=0;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}